﻿using System;
using System.Collections.Generic;
using MagistrAPI.Enums;
using MagistrAPI.Integration;
using ZedGraphControl;

namespace MagistrWPFUI.Presenter
{
    public class ModelSupplier
    {
        private Dictionary<Equations, List<double>> _rezults;
        private readonly IIntegrator _integrator;
        private IGraphic _graphic;
        private static Characteristics[] _characteristicses;
        private static ZedGraphUserControl _zgc;

        public ModelSupplier(ZedGraphUserControl zgc)
        {
            _integrator = new RK4Integrator();
            if (_zgc == null)
            {
                _zgc = zgc;
            }
        }

        public Characteristics[] Characteristicses
        {
            get
            {
                return _characteristicses ?? (_characteristicses = new[]
                                                                       {
                                                                           Characteristics.V,
                                                                           Characteristics.H,
                                                                           Characteristics.M,
                                                                           Characteristics.Al,
                                                                           Characteristics.Fi,
                                                                           Characteristics.Gam,
                                                                           Characteristics.Q,
                                                                           Characteristics.W,
                                                                           Characteristics.Gx,
                                                                           Characteristics.Gy,
                                                                           Characteristics.Gz,
                                                                       });
            }
        }

        public void Integrate(double[] initParams)
        {
            _rezults = _integrator.Integrate(0, 400, 0.5, 0.5, 0.001, initParams);
            _graphic = new ZedGraphGraphic(_rezults, _zgc);
        }

        public void DrawGraphic(Characteristics characteristic)
        {
            if (_graphic == null)
            {
                throw new Exception("Сначала нужно проинтегрировать");
            }
            _graphic.Draw(characteristic);
        }
    }
}
